package com.qcby.shujia.demo.controller;

import com.qcby.shujia.demo.anno.PreAuth;
import com.qcby.shujia.demo.common.web.ResultData;
import com.qcby.shujia.demo.entity.Tright;
import com.qcby.shujia.demo.entity.User;
import com.qcby.shujia.demo.entity.vo.UserVo;
import com.qcby.shujia.demo.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @className: UserController
 * @description: 用户controller
 * @author: whz
 * @date: 2021/9/19
 **/
@RestController
@RequestMapping("/user")
public class UserController {
    protected Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private UserService userService;
    @RequestMapping("/insert")
    public int insert(User user,@RequestParam List<Integer> roleids){
        int i=userService.insert(user,roleids);
        return i;
    }
    @RequestMapping("/delete")
    public int delete(Integer id){
        int i=userService.deleteById(id);
        return i;
    }
    @PreAuth("user:selectAll")
    @GetMapping("/selectAll")
    public List<User> selectAll(){
       List<User> li= userService.selectAll();

       return li;
    }
    @GetMapping("/selectUrById")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",
            value = "要查找的用户id", required = true,
            dataType = "integer")})
    public UserVo selectUrById(Integer id){
        UserVo userVo = userService.selectUrById(id);
        return userVo;
    }
    @RequestMapping("/deletedisp")
    public int deletedisp(int[] ids){
        int i=userService.deletedisp(ids);
        return i;
    }
    @RequestMapping("/update")
    public int update(User user,@RequestParam List<Integer> uproleids){
       int i= userService.update(user,uproleids);
        return i;
    }


//    @RequestMapping("listpage")
//    public ResultData listpage(int pageNo, int pageSize){
//       return ResultData.ok(userService.listpage(pageNo,pageSize));
//    }

}
